<!--
 	* @author  dumeng
-->
<template>
  <section class="staffserve-news-preview">
    <el-dialog v-el-drag-dialog :close-on-click-modal="false" :visible.sync="state" title="预览" width="375px" center :before-close="handleCancel">
      <section v-loading="loading" class="preview-container">
        <section class="content" :class="{'b0': detail.commentState === 0 || detail.commentState === 1}">
          <section v-if="detail.mainTitle" class="title">
            <span>{{ detail.mainTitle }}</span>
          </section>
          <section
            v-if="detail.publisher && detail.publishTime"
            class="time"
          >发布人：{{ detail.publisher }}&nbsp;&nbsp;&nbsp;&nbsp;发布时间：{{ detail.publishTime.length > 10 ? detail.publishTime.substring(0, 10) : detail.publishTime }}</section>
          <section v-if="detail.pageview || detail.shareNumber || detail.publishTime" class="time">
            <span v-if="detail.pageview">{{ detail.pageview }}次浏览&nbsp;&nbsp;</span>
            <span v-if="detail.shareNumber">{{ detail.shareNumber }}次分享&nbsp;&nbsp;</span>
          </section>
          <section class="data">
            <template v-if="detail.videoList && detail.videoList.length > 0">
              <div v-for="item in detail.videoList" :key="item.attachmentId">
                <video :src="view + item.attachmentId" controls />
              </div>
            </template>
            <template v-if="detail.picList && detail.picList.length > 0">
              <div v-for="item in detail.picList" :key="item.attachmentId">
                <img :src="view + item.attachmentId" alt />
                <p class="explain">{{ item.explain }}</p>
              </div>
            </template>
            <p v-if="detail.text" class="news-text" v-html="detail.text" />
          </section>
          <section v-if="detail.fileList && detail.fileList.length" class="file">
            <div class="row1">
              <div class="left">附件</div>
            </div>
            <div v-for="i in detail.fileList" :key="i.attachmentId" class="fitem">
              <img
                src=""
                alt
              />
              <span>{{ i.attachmentName }}</span>
            </div>
          </section>
          <section v-if="detail.param1" class="right-bottom">
            <div class="author">责任编辑：{{ detail.param1 }}</div>
          </section>
        </section>
      </section>
      <section slot="footer" class="dialog-footer">
        <el-button style="padding: 8px 30px;" @click="handleCancel()">关 闭</el-button>
      </section>
    </el-dialog>
  </section>
</template>

<script>
import elDragDialog from '@/directive/el-drag-dialog' // base on element-ui
export default {
  name: 'StaffserveNewsPreview',
  directives: { elDragDialog },
  props: {
    id: {
      type: String,
      default: ''
    },
    fun: {
      type: Function,
      default: () => { }
    }
  },
  data() {
    return {
      loading: false,
      detail: {},
      state: true,
      view: '/API-DOCUMENT/document/file/download?id='
    }
  },
  created() {
    this.getData()
  },
  methods: {
    /**
     * 根编辑回显
     */
    getData() {
      this.loading = true
      this.fun({ id: this.id }).then(res => {
        this.loading = false
        this.detail = res.data.data
      }).catch(() => {
        this.loading = false
      })
    },
    handleCancel() {
      this.$emit('closeSet')
    }
  }
}
</script>

<style lang="scss">
@import '@/styles/mixin.scss';
.staffserve-news-preview {
  position: relative;
  .el-dialog .el-dialog__body {
    padding: 10px 10px 10px 20px !important;
  }
  .preview-container {
    height: 80vh;
    position: relative;
  }
  .content {
    padding: 10px 10px 10px 0;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    overflow-y: auto;
    &::-webkit-scrollbar {
      width: 8px; /*对垂直流动条有效*/
      height: 1px; /*对水平流动条有效*/
    }
    /** 滚动条轨道*/
    &::-webkit-scrollbar-track {
      box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.1);
      background-color: white;
      border-radius: 3px;
    }
    /** 滚动条里面小方块*/
    &::-webkit-scrollbar-thumb {
      height: 32px;
      border-radius: 5px;
      box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.1);
      background-color: #eaeaea;
    }
    .title {
      font-size: 20px;
      font-family: PingFang SC Medium, PingFang SC Medium-Medium;
      font-weight: 700;
      text-align: left;
      color: #333333;
    }
    .time {
      margin-top: 15px;
      margin-bottom: 15px;
      font-size: 12px;
      font-family: PingFang SC Regular, PingFang SC Regular-Regular;
      font-weight: 400;
      text-align: left;
      color: #999999;
    }
    .data {
      margin-top: 7px;
      img,
      video {
        width: 100%;
      }
      .explain {
        text-align: center;
      }
    }
    .file {
      margin: 12px 0;
      width: 100%;
      background: linear-gradient(#fff3ed 0%, #ffeadf 100%);
      border-radius: 16px;
      padding: 10px;
      padding-top: 0;
      .row1 {
        display: flex;
        height: 40px;
        font-family: PingFang SC Medium, PingFang SC Medium-Medium;
        line-height: 40px;
        border-bottom: 1px dotted #f5c7ac;
        .left {
          flex: 1;
          text-align: left;
          font-size: 14px;
          font-weight: 500;
          color: #333333;
        }
        .right {
          flex: 1;
          text-align: right;
          .btn {
            display: inline-block;
            width: 58px;
            text-align: center;
            height: 24px;
            border-radius: 12px;
            line-height: 24px;
            color: #fff;
            background: #eb523c;
          }
        }
      }
      .fitem {
        margin-top: 10px;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
        word-break: break-all;
        img {
          width: 24px;
          height: 24px;
          vertical-align: middle;
        }
        span {
          margin-left: 10px;
          font-size: 12px;
          color: #666666;
        }
      }
    }
    .right-bottom {
      margin-top: 20px;
      height: 30px;
      font-family: PingFang SC Regular, PingFang SC Regular-Regular;
      font-weight: 400;
      text-align: left;
      color: #999999;
      .author {
        text-align: right;
        font-size: 13px;
      }
    }
    .news-text {
      font-size: 15px;
      video,
      audio,
      img {
        display: block;
        max-width: 100% !important;
        height: auto !important;
      }
    }
    .common-container {
      h4 {
        font-size: 14px;
        color: #333;
      }
      .comment-con {
        position: relative;
        min-height: 150px;
        .comment-item {
          display: flex;
          margin-bottom: 30px;
          &:last-child {
            margin-bottom: 10px;
          }

          & > img {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            margin-right: 10px;
            flex: 0 0 auto;
          }

          .comment-item-right {
            .comment-item-right-content {
              display: flex;
              justify-content: space-between;
              .comment-name {
                font-size: 14px;
                font-family: PingFangSC-Regular;
                font-weight: bold;
                color: rgba(51, 51, 51, 1);
                line-height: 18px;
              }
            }

            .comment-time {
              display: flex;
              align-items: center;
              font-size: 12px;
              font-family: PingFangSC-Regular;
              font-weight: 400;
              color: #999;
              line-height: 18px;
              .reply {
                margin-left: 10px;
                color: #666;
              }
            }

            .comment-content {
              width: 293px;
              font-size: 14px;
              font-family: PingFangSC-Regular;
              font-weight: 400;
              color: rgba(51, 51, 51, 1);
              line-height: 21px;
              margin-top: 5px;
              word-wrap: break-word;
            }
            .comment-img {
              display: flex;
              margin: 5px 0;
              .van-image {
                margin-left: 5px;
                &:first-child {
                  margin-left: 0;
                }
                img {
                  width: 82px;
                  height: 82px;
                  border-radius: 6px;
                }
              }
            }
            .reply-content {
              width: 100%;
              background-color: #fafafa;
              padding: 5px 10px;
              margin-top: 5px;
              li {
                margin-bottom: 20px;
                position: relative;
                &:last-child {
                  margin-bottom: 0;
                  &:after {
                    display: none;
                  }
                }
                &:after {
                  left: 0;
                  right: 0;
                  width: auto;
                  height: 1px;
                  position: absolute;
                  z-index: 0;
                  bottom: -10px;
                  content: '';
                  background-image: -webkit-gradient(
                    linear,
                    left bottom,
                    left top,
                    color-stop(50%, #ececec),
                    color-stop(0, transparent)
                  );
                  background-image: linear-gradient(
                    0deg,
                    #ececec 50%,
                    transparent 0
                  );
                }
              }
              .reply-info {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
                .replyer {
                  color: #9e9e9e;
                  span {
                    color: #666;
                  }
                }
                .reply-info {
                  color: #333;
                }
              }
              .reply-img {
                display: flex;
                margin: 7px 0;
                .van-image {
                  margin-left: 5px;
                  &:first-child {
                    margin-left: 0;
                  }
                  img {
                    width: 82px;
                    height: 82px;
                    border-radius: 6px;
                  }
                }
              }
              .reply-time {
                color: #999;
                font-size: 12px;
                margin-top: 4px;
                .reply {
                  margin-left: 10px;
                  color: #666;
                }
              }
              .get-son {
                text-align: center;
                @include font-color($mainColor);
              }
            }
          }
        }
      }
    }
  }
  .menu {
    position: absolute;
    right: 15px;
    bottom: 155px;
    width: 50px;
    height: 225px;
    z-index: 9;
    .menuItem {
      margin: 10px auto;
      width: 47px;
      height: 47px;
      border-radius: 50%;
      background: rgba(0, 0, 0, 0.75);
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      .icon {
        width: 16px;
        height: 16px;
        flex: 0 0 auto;
      }
      .num {
        font-size: 10px;
        font-family: PingFang SC Regular, PingFang SC Regular-Regular;
        font-weight: 400;
        color: #ffffff;
      }
    }
  }
}
</style>
